Skip to content

Conversation

aganisgash
Copy link
Contributor

All other mock functions use make_acc_non_empty to etch a single byte onto empty accounts, which prevents Solidity's extcodesize check from failing when mocking calls to addresses without existing bytecode.

Makes mockCalls_1Call consistent with the other mock cheatcodes and ensures mocked calls work correctly in all scenarios.

@zerosnacks
Copy link
Member

This makes sense to me, I am not sure why this was treated as a special case

For context:

// Etches a single byte onto the account if it is empty to circumvent the `extcodesize`
// check Solidity might perform.
fn make_acc_non_empty(callee: &Address, ecx: &mut CheatsCtxt) -> Result {
let acc = ecx.journaled_state.load_account(*callee)?;
let empty_bytecode = acc.info.code.as_ref().is_none_or(Bytecode::is_empty);
if empty_bytecode {
let code = Bytecode::new_raw(Bytes::from_static(&[0u8]));
ecx.journaled_state.set_code(*callee, code);
}
Ok(Default::default())
}

@zerosnacks zerosnacks self-requested a review August 27, 2025 15:03
@aganisgash
Copy link
Contributor Author

This makes sense to me, I am not sure why this was treated as a special case

For context:

// Etches a single byte onto the account if it is empty to circumvent the `extcodesize`
// check Solidity might perform.
fn make_acc_non_empty(callee: &Address, ecx: &mut CheatsCtxt) -> Result {
let acc = ecx.journaled_state.load_account(*callee)?;
let empty_bytecode = acc.info.code.as_ref().is_none_or(Bytecode::is_empty);
if empty_bytecode {
let code = Bytecode::new_raw(Bytes::from_static(&[0u8]));
ecx.journaled_state.set_code(*callee, code);
}
Ok(Default::default())
}

Maybe just a copy-paste oversight. All the other mock functions follow the same pattern with make_acc_non_empty, so this one likely got missed when the code was initially written.

@grandizzy
Copy link
Collaborator

I think we want a sig to bypass that at some point but subject to discussion #10703 (comment)

zerosnacks
zerosnacks previously approved these changes Aug 27, 2025
@zerosnacks zerosnacks self-requested a review August 27, 2025 15:10
@zerosnacks zerosnacks dismissed their stale review August 27, 2025 15:11

pending discussion

@grandizzy
Copy link
Collaborator

grandizzy commented Aug 27, 2025

I think that's fine but could be breaking change for some projects assuming that will revert

@grandizzy grandizzy self-assigned this Oct 2, 2025
@zerosnacks
Copy link
Member

Hi @aganisgash would you mind also making this change for mockCall_1Call and mockCall_3Call?

ccx.ecx.journaled_state.load_account(*callee)?;

ccx.ecx.journaled_state.load_account(*callee)?;

This aligns the behavior for all mockCall*

@aganisgash
Copy link
Contributor Author

@zerosnacks Sure, all fixed

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you

@zerosnacks zerosnacks changed the title fix(cheatcodes): use make_acc_non_empty in mockCalls_1Call for consistency fix(cheatcodes): use make_acc_non_empty in mockCalls_1Call, mockCall_1Call, mockCall_3Call for consistency Oct 15, 2025
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zerosnacks zerosnacks changed the title fix(cheatcodes): use make_acc_non_empty in mockCalls_1Call, mockCall_1Call, mockCall_3Call for consistency fix(cheatcodes): use make_acc_non_empty in mockCalls_1Call, mockCall_1Call, mockCall_3Call for consistency Oct 15, 2025
@zerosnacks zerosnacks merged commit 9e12190 into foundry-rs:master Oct 15, 2025
29 of 31 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Oct 15, 2025
@jenpaff jenpaff moved this from Done to Completed in Foundry Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants